﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace PrinteMaster
{
    class Function
    {
        /// <summary>
        /// 该函数用于实现获得焦点时显示空值，不获得焦点时显示提示的功能。(普通输入框)
        /// </summary>
        /// <param name="tb">需要实现此功能的TextBox</param>
        /// <param name="hits">此功能实现时需要的提示</param>
        public static void inputText(TextBox tb,string hits)
        {
            if (tb.Text.Equals(hits))
            {
                tb.Text = "";
            }
            // 如果为空，则变为提示信息
            else if (tb.Text.Equals(""))
            {
                tb.Text = hits;
            }
        }

        /// <summary>
        /// 用于实现只能输入整数的功能.
        /// </summary>
        /// <param name="sender">原样传递</param>
        /// <param name="e">原样传递</param>
        public static void inputInt(object sender, KeyPressEventArgs e)
        {
            if (!Char.IsNumber(e.KeyChar) && e.KeyChar != (char)8)
            {
                e.Handled = true;
            }
        }
        /// <summary>
        /// 该函数用于实现获得焦点时显示空值，不获得焦点时显示提示的功能。(密码输入框)
        /// </summary>
        /// <param name="tb"></param>
        /// <param name="hits"></param>
        public static void inputPassWord(TextBox tb, string hits)
        {
            // 如果账号为提示信息，则变为空
            if (tb.Text.Equals(hits))
            {
                tb.Text = "";
                tb.UseSystemPasswordChar = true;
            }
            // 如果为空，则变为提示信息
            else if (tb.Text.Equals(""))
            {
                tb.Text = hits;
                tb.UseSystemPasswordChar = false;
            }
        }

        /// <summary>
        /// 判断当前密码的合法性
        /// </summary>
        /// <param name="tb"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public static bool isPassWordValue(TextBox tb,int value=8)
        {
            if (tb.Text.Length < value)
            {
                return false;
            }
            return true;
        }
        /// <summary>
        /// 判断当前密码的合法性
        /// </summary>
        /// <param name="str"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public static bool isPassWordValue(string str, int value = 8)
        {
            if (str.Length < value)
            {
                return false;
            }
            return true;
        }
    }
}
